package com.jindianjichi.infra.rpc;

import com.jindianjichi.infra.entity.UserInfo;
import com.jindianjichi.auth.api.UserFeignService;
import com.jindianjichi.auth.entity.AuthUserDTO;
import com.jindianjichi.auth.entity.Result;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class UserRpc {
    @Resource
    private UserFeignService userFeignService;


    public UserInfo getUserInfo(String userName) {
        AuthUserDTO authUserDTO = new AuthUserDTO();
        authUserDTO.setUserName(userName);
        Result<AuthUserDTO> userDTO = userFeignService.getUserInfo(authUserDTO);
        UserInfo userInfo= new UserInfo();
        if (!userDTO.getSuccess()) {
            return  userInfo;
        }
        AuthUserDTO data = userDTO.getData();
        userInfo.setUserName(data.getUserName());
        userInfo.setNickName(data.getNickName());
        userInfo.setAvatar(data.getAvatar());
        return userInfo;


    }
}
